home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2007 December / PCWKCD1207B.iso / Blogowanie poza sfera / Scribefire-1.4.2 / scribefire-1.4.2-fx+fl.xpi / chrome / content / history.js < prev    next >
Encoding:
JavaScript  |  2007-07-24  |  7.4 KB  |  187 lines

  1. /*
  2. History javascript
  3. --------------------------------
  4. A poor attempt to keep all history functions here
  5. */
  6.  
  7. var PFFTempHistoryObject = new XML();
  8. var pffDebugTempHistObject = [];
  9.  
  10. //TODO: Make more generic for re-use!!
  11. performancingUtil.prototype.loadHistoryXMLFile = function(){
  12.     var file = gPerformancingUtil.getHistoryXMLFile();
  13.     var f2 = PerFormancingFileIO.open(file.path);
  14.     var theXMLString = null;
  15.     if(f2.exists()){
  16.         theXMLString = PerFormancingFileIO.read(file, "UTF-8");
  17.         var theHistoryXML = new XML(theXMLString);
  18.         return theHistoryXML;
  19.     }else{
  20.         //dump('PerFormancing XML File does not exists!');
  21.         return false;
  22.     }
  23. }
  24.  
  25. //TODO: Make more generic for use with Notes!
  26. performancingUtil.prototype.getHistoryXMLFile = function(){
  27.     var file = PerFormancingDirIO.get("ProfD");
  28.     file.append("extensions");
  29.     file.append('performancing_history.xml');
  30.     return file;
  31. }
  32.  
  33. performancingUtil.prototype.addHistoryItemToEditor = function(theElement){
  34. /*
  35.    Todo:
  36.    - Load Content
  37.    - Load Subject
  38.    - Load Categories
  39.    - Display 'Publish as New' and 'Publish as Edit'
  40. */
  41.     var thePostID = theElement.getAttribute("postid");
  42.     var theDateCreated = theElement.getAttribute("date");
  43.     var histFile = gPerformancingUtil.loadHistoryXMLFile();
  44.     
  45.     var theBlogXML = new XML(histFile);
  46.     pffDebugTempHistObject = theBlogXML;
  47.     try{
  48.         //dump("The Read History XML: " + theBlogXML..entry + '\n' + "aPostId to get:" + thePostID + '\n')
  49.         var theEntry = theBlogXML..entry.(postid == thePostID );
  50.         
  51.         //Now load everything
  52.         //First Focus the Source
  53.         var tabbox = document.getElementById("performancing-editor-tabbox"); 
  54.         //tabbox.selectedIndex = 1;
  55.         
  56.         //convert back to html
  57.         var theContent = theEntry.content.toString();
  58.         theContent = theContent.replace(/</gi, "<");
  59.         theContent = theContent.replace(/>/gi, ">");
  60.         
  61.         /*
  62.         //Then Load the contents
  63.         var winPreview = document.getElementById("performancing-preview-display");
  64.         //winPreview.contentWindow.document.body.innerHTML = theContent;
  65.         document.getElementById("performancing-message-source").value = theContent;
  66.         performancingMidas.syncNormalTab();
  67.         */
  68.         
  69.         //var tabbox = document.getElementById("performancing-editor-tabbox");
  70.         if(tabbox.selectedIndex == 0 || tabbox.selectedIndex == 2){//Rich or preview
  71.             var winNormal = document.getElementById("performancing-message");
  72.             winNormal.contentWindow.document.body.innerHTML = theContent;
  73.         }else if(tabbox.selectedIndex == 1){ //Source
  74.             document.getElementById("performancing-message-source").value = theContent;
  75.         }else{
  76.             //PerFormancing Error: Could not find Note content, please contact the author
  77.             var localeString = performancingUI.getLocaleString('nonotecontent', []);
  78.             alert(localeString);
  79.         }
  80.         var winPreview = document.getElementById("performancing-preview-display");
  81.         //winPreview.contentWindow.document.body.innerHTML = theContent;
  82.         document.getElementById("performancing-message-source").value = theContent;
  83.         performancingMidas.syncNormalTab();
  84.         
  85.         //Then Load the Title
  86.         var theTitle = theEntry.title.toString();
  87.         document.getElementById("performancing-editor-subject").value = theTitle;
  88.         
  89.         //Load the categories
  90.         var tempArray = theEntry.categories.split(",");
  91.         gPerformancingUtil.setCategoriesSidebar(tempArray, false);
  92.         
  93.         //Show Republish button and set attributes
  94.         var pubButton = document.getElementById("performancing-republish-button");
  95.         var editButtons = document.getElementById("post-edit-buttons");
  96.         pubButton.setAttribute("lastpostid", thePostID);
  97.         pubButton.setAttribute("datecreated", theDateCreated);
  98.         editButtons.hidden = false;
  99.         
  100.         return true;
  101.     }catch(e){
  102.         //alert("History Error: " + e);
  103.         return true;
  104.     }
  105.     
  106. }
  107.  
  108. performancingUtil.prototype.clearHistoryXMLFile = function(){
  109.     var file = gPerformancingUtil.getHistoryXMLFile();
  110.     var theXMLFile = null;
  111.     var theBlogXML = null;
  112.     //Doesn't exist, so let's create it.
  113.     if(!file.exists()){
  114.         //dump('Creating HISTORY file: \n');
  115.         theBlogXML = <historylist>
  116.                         <list></list>
  117.                      </historylist>;
  118.         PFFTempHistoryObject = theBlogXML;
  119.         PerFormancingFileIO.create(file);
  120.         var rv = PerFormancingFileIO.write(file, theBlogXML.toString(), "w", "UTF-8");
  121.         if(!rv) {
  122.             var localeString = performancingUI.getLocaleString('cannotwritetofile', []);
  123.             alert(localeString);
  124.         }
  125.     }else if(file.exists()){
  126.          var theXMLFile = PerFormancingFileIO.open(file.path);
  127.          theBlogXML = <historylist>
  128.                         <list></list>
  129.                      </historylist>;
  130.          PFFTempHistoryObject = theBlogXML;
  131.          var newWrite = PerFormancingFileIO.write(file, theBlogXML.toString(), "w", "UTF-8");
  132.          if(!newWrite) {
  133.             var localeString = performancingUI.getLocaleString('cannotwritetofile', []);
  134.             alert(localeString);
  135.          }
  136.     }
  137. }
  138.  
  139. performancingUtil.prototype.setHistoryXML = function(thePostID, theContent, theTitle, theCategories, theDateCreated){
  140.     //PFFTempHistoryObject
  141.     PFFTempHistoryObject.list.entry +=
  142.                             <entry>
  143.                                 <postid>{thePostID}</postid>
  144.                                 <content>{theContent}</content>
  145.                                 <title>{theTitle}</title>
  146.                                 <categories>{theCategories}</categories>
  147.                                 <datecreated>{theDateCreated}</datecreated>
  148.                             </entry>;
  149. }
  150.  
  151.     
  152. //TODO: Make more generic for use with Notes!
  153. //gPerformancingUtil.saveHistoryXMLFile(thePostID, theContent, theTitle, theCategories, theDateCreated);
  154. performancingUtil.prototype.saveHistoryXMLFile = function(){
  155.     //We need to get this from a file and theBlogXML = new XML(theFilesStringContents);
  156.     var file = gPerformancingUtil.getHistoryXMLFile();
  157.     if(file.exists()){
  158.         var theXMLFile = PerFormancingFileIO.open(file.path);
  159.         //var theXMLString = PerFormancingFileIO.read(theXMLFile, "UTF-8");
  160.         //theBlogXML = new XML(theXMLString);
  161.         /*theBlogXML = <historylist>
  162.                         <list></list>
  163.                      </historylist>;
  164.         */
  165.         //The Content for each Blog
  166.         /*theBlogXML.list.entry +=
  167.                                     <entry>
  168.                                         <postid>{thePostID}</postid>
  169.                                         <content>{theContent}</content>
  170.                                         <title>{theTitle}</title>
  171.                                         <categories>{theCategories}</categories>
  172.                                         <datecreated>{theDateCreated}</datecreated>
  173.                                     </entry>;*/
  174.         //Write to file (save changes)
  175.         var newWrite = PerFormancingFileIO.write(file, PFFTempHistoryObject.toString(), "w", "UTF-8");
  176.         PFFTempHistoryObject = null;
  177.         if(!newWrite) {
  178.             var localeString = performancingUI.getLocaleString('cannotwritetofile', []);
  179.             alert(localeString);
  180.         }
  181.                                 
  182.         return true;
  183.     }else{
  184.         return false;
  185.     }
  186. }
  187.